<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{title}}</h1>
        <ul>
            <li v-for="(item,i) in products">姓名： {{item.name}}
                <button @click="changeStock(item,item.stock - 1)">-</button>
                <span v-if="item.stock>0">剩余阳寿：{{item.stock}}</span>
                <span v-else>已死亡</span>
                <button @click="changeStock(item,item.stock + 1)">+</button>
                <button @click="remove(i)">删除</button>
            </li>
        </ul>
    </div>
    <script src="./vue.min.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                title: '生死薄管理系统',
                products: [
                    {name: '黄书狼',stock: 12},
                    {name: '猪回笼',stock: 10},
                    {name: '彩虹涛',stock: 5}
                ],  
            },
            methods: {
                    remove(i){
                        this.products.splice(i,1);
                    },
                    changeStock(products, newStock){
                        if(newStock < 0){
                            newStock = 0;
                        }
                        products.stock = newStock;
                    }
                }
        })
    </script>
</body>
</html>